/**
 * <copyright>
 * </copyright>
 *

 */
package it.spoli.talkMe.impl;

import it.spoli.talkMe.Interaction;
import it.spoli.talkMe.Message;
import it.spoli.talkMe.Subject;
import it.spoli.talkMe.TalkMePackage;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>System</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link it.spoli.talkMe.impl.SystemImpl#getName <em>Name</em>}</li>
 *   <li>{@link it.spoli.talkMe.impl.SystemImpl#getPackage <em>Package</em>}</li>
 *   <li>{@link it.spoli.talkMe.impl.SystemImpl#getMessages <em>Messages</em>}</li>
 *   <li>{@link it.spoli.talkMe.impl.SystemImpl#getSubjects <em>Subjects</em>}</li>
 *   <li>{@link it.spoli.talkMe.impl.SystemImpl#getInteractions <em>Interactions</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class SystemImpl extends MinimalEObjectImpl.Container implements it.spoli.talkMe.System
{
  /**
   * The default value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
  protected static final String NAME_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
  protected String name = NAME_EDEFAULT;

  /**
   * The cached value of the '{@link #getPackage() <em>Package</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getPackage()
   * @generated
   * @ordered
   */
  protected it.spoli.talkMe.Package package_;

  /**
   * The cached value of the '{@link #getMessages() <em>Messages</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getMessages()
   * @generated
   * @ordered
   */
  protected EList<Message> messages;

  /**
   * The cached value of the '{@link #getSubjects() <em>Subjects</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getSubjects()
   * @generated
   * @ordered
   */
  protected EList<Subject> subjects;

  /**
   * The cached value of the '{@link #getInteractions() <em>Interactions</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getInteractions()
   * @generated
   * @ordered
   */
  protected EList<Interaction> interactions;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected SystemImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return TalkMePackage.Literals.SYSTEM;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getName()
  {
    return name;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setName(String newName)
  {
    String oldName = name;
    name = newName;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, TalkMePackage.SYSTEM__NAME, oldName, name));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public it.spoli.talkMe.Package getPackage()
  {
    return package_;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetPackage(it.spoli.talkMe.Package newPackage, NotificationChain msgs)
  {
    it.spoli.talkMe.Package oldPackage = package_;
    package_ = newPackage;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, TalkMePackage.SYSTEM__PACKAGE, oldPackage, newPackage);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setPackage(it.spoli.talkMe.Package newPackage)
  {
    if (newPackage != package_)
    {
      NotificationChain msgs = null;
      if (package_ != null)
        msgs = ((InternalEObject)package_).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - TalkMePackage.SYSTEM__PACKAGE, null, msgs);
      if (newPackage != null)
        msgs = ((InternalEObject)newPackage).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - TalkMePackage.SYSTEM__PACKAGE, null, msgs);
      msgs = basicSetPackage(newPackage, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, TalkMePackage.SYSTEM__PACKAGE, newPackage, newPackage));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Message> getMessages()
  {
    if (messages == null)
    {
      messages = new EObjectContainmentEList<Message>(Message.class, this, TalkMePackage.SYSTEM__MESSAGES);
    }
    return messages;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Subject> getSubjects()
  {
    if (subjects == null)
    {
      subjects = new EObjectContainmentEList<Subject>(Subject.class, this, TalkMePackage.SYSTEM__SUBJECTS);
    }
    return subjects;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Interaction> getInteractions()
  {
    if (interactions == null)
    {
      interactions = new EObjectContainmentEList<Interaction>(Interaction.class, this, TalkMePackage.SYSTEM__INTERACTIONS);
    }
    return interactions;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case TalkMePackage.SYSTEM__PACKAGE:
        return basicSetPackage(null, msgs);
      case TalkMePackage.SYSTEM__MESSAGES:
        return ((InternalEList<?>)getMessages()).basicRemove(otherEnd, msgs);
      case TalkMePackage.SYSTEM__SUBJECTS:
        return ((InternalEList<?>)getSubjects()).basicRemove(otherEnd, msgs);
      case TalkMePackage.SYSTEM__INTERACTIONS:
        return ((InternalEList<?>)getInteractions()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case TalkMePackage.SYSTEM__NAME:
        return getName();
      case TalkMePackage.SYSTEM__PACKAGE:
        return getPackage();
      case TalkMePackage.SYSTEM__MESSAGES:
        return getMessages();
      case TalkMePackage.SYSTEM__SUBJECTS:
        return getSubjects();
      case TalkMePackage.SYSTEM__INTERACTIONS:
        return getInteractions();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case TalkMePackage.SYSTEM__NAME:
        setName((String)newValue);
        return;
      case TalkMePackage.SYSTEM__PACKAGE:
        setPackage((it.spoli.talkMe.Package)newValue);
        return;
      case TalkMePackage.SYSTEM__MESSAGES:
        getMessages().clear();
        getMessages().addAll((Collection<? extends Message>)newValue);
        return;
      case TalkMePackage.SYSTEM__SUBJECTS:
        getSubjects().clear();
        getSubjects().addAll((Collection<? extends Subject>)newValue);
        return;
      case TalkMePackage.SYSTEM__INTERACTIONS:
        getInteractions().clear();
        getInteractions().addAll((Collection<? extends Interaction>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case TalkMePackage.SYSTEM__NAME:
        setName(NAME_EDEFAULT);
        return;
      case TalkMePackage.SYSTEM__PACKAGE:
        setPackage((it.spoli.talkMe.Package)null);
        return;
      case TalkMePackage.SYSTEM__MESSAGES:
        getMessages().clear();
        return;
      case TalkMePackage.SYSTEM__SUBJECTS:
        getSubjects().clear();
        return;
      case TalkMePackage.SYSTEM__INTERACTIONS:
        getInteractions().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case TalkMePackage.SYSTEM__NAME:
        return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
      case TalkMePackage.SYSTEM__PACKAGE:
        return package_ != null;
      case TalkMePackage.SYSTEM__MESSAGES:
        return messages != null && !messages.isEmpty();
      case TalkMePackage.SYSTEM__SUBJECTS:
        return subjects != null && !subjects.isEmpty();
      case TalkMePackage.SYSTEM__INTERACTIONS:
        return interactions != null && !interactions.isEmpty();
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString()
  {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (name: ");
    result.append(name);
    result.append(')');
    return result.toString();
  }

} //SystemImpl
